import Cookies from 'js-cookie'

export enum EnumStorage {
	'ACCESS_TOKEN' = 'accessToken',
	'USER' = 'user'
}

export const getAccessToken = () => {
	const accessToken = Cookies.get(EnumStorage.ACCESS_TOKEN)
	return accessToken || null
}

export const saveTokenStorage = (token: string) => {
	Cookies.set(EnumStorage.ACCESS_TOKEN, token, {
		domain: 'localhost',
		sameSite: 'strict',
		expires: 1
	})
}

export const removeTokenStorage = () => {
	Cookies.remove(EnumStorage.ACCESS_TOKEN)
}

export const getUser = () => {
	const cookie_data = Cookies.get(EnumStorage.USER)
	if (typeof cookie_data !== 'undefined') {
		return JSON.parse(cookie_data)
	}
	return null
}
